<?php
/**
 * Created by PhpStorm.
 * User: libin
 * Date: 2017/9/6
 * Time: 下午4:24
 */
namespace App;

use App\Animal\Animal;

class Zoo
{
    /**
     * @var array
     */
    private $animalsCollection;

    public function addAnimal(Animal $animal)
    {
        $this->animalsCollection[] = $animal;
    }

    public function watch()
    {
        foreach ($this->animalsCollection as $animal) {
            if ($animal instanceof Animal) {
                $animal->breath();
                $animal->eat();
                $animal->sleep();
            }
            echo '<br/><br/>';
        }
    }

    public function kill()
    {
        echo '我要挑一个拿去祭天: <br/>';
        $count = count($this->animalsCollection);
        $random = mt_rand(0,  $count - 1);
        $animalWillBeDied = $this->animalsCollection[$random];
        echo $animalWillBeDied->name . '将要被杀掉<br/>';
        $animalWillBeDied->scream();
        echo '开玩笑的，哈哈。。。<br/>';
    }
}
